/**
 * Created by no1 on 2015/5/29.
 */


'use strict';
var mysql = require('./mysql.js');
var C = require('../config/index');
var F = require('../common/function');
//var MPosts=require('../models/posts.js');
//var MTags=require('../models/tags.js');
//var MUser=require('../models/users.js');
//var Mman = require('../common/man.js');
var _ = require('underscore');
var _s = require('underscore.string');
var md5 = require('md5');
var request = require('koa-request');
var async_request = require('request');
_.v = require('validator');


/*
 @todo API50. 地图显示
 */
exports.mapInfo = function*(Env) {
    let fields = Env.I;
    let loginStatus = fields.loginStatus;
    let act = fields['act'];
    let mapid = fields['mapid'] ? parseInt(fields.mapid) : 0;
    let result;
    if (mapid < 1) { //参数无效
        return F.returnMsg(400, '参数错误', 3);
    } else {
        switch (mapid) {
            case 1 :
                var sql = 'SELECT  wshopid,CONCAT("【屈臣氏】",mw.name) as title,' +
                    'mw.amap_lng as longitude,' +
                    'mw.amap_lat as latitude,' +
                    'mw.shopaddress as detail' +
                    ' FROM mh_watsons mw WHERE mw.lv=4 AND chnstatus=1 AND mw.new=0 LIMIT 0,150';
                result = yield mysql.query(sql);
                if (result.length > 0) {
                    return F.returnMsg(200, '屈臣氏店面', 3, {title: '屈臣氏店面地图', geo: result});
                } else {
                    return F.returnMsg(300, '无数据', 3);
                }
                break;
            default :
                return F.returnMsg(400, '参数错误', 3);
        }
    }

};


